package com.example.clienta.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        String referer=httpServletRequest.getParameter("referer");
        if(referer==null){
            referer="http://localhost:8880/login.html?logout";
        }
        httpServletResponse.sendRedirect("http://localhost:8880/logout?referer="+referer);
    }
}
